<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-07-06 17:01:24
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description:   :gridOps="gridOptions" 
-->
<template>
	<el-container style="height: 100%">
		<el-main style="height: 100%">
			<sc-VxeTable
				ref="xGrid1"
				:gridEvts="gridEvents"
				:tablecode="'basedata_businessCompany_category'"
				:gridOps="gridOps"
				:url="this.$API.basedata.businessCompany.category.list"
			>
			</sc-VxeTable>
		</el-main>
		<save-dialog
			v-if="dialog.save"
			ref="saveDialog"
			@success="handleSuccess"
			@closed="dialog.save = false"
		>
		</save-dialog>
	</el-container>
</template>
<script>
// import { useRouter } from "vue-router";
// import { VXETable } from 'vxe-table';
import { ElNotification } from "element-plus";
import skCategory from "@/components/skCategory";
import SaveDialog from "./save";
export default {
	components: {
		SaveDialog,
		skCategory,
	},
	name: "basedata_businessCompany_category",
	data() {
		return {
			dialog: {
				save: false,
			},

			gridEvents: {
				cellDblclick: ({ row }) => {
					this.edit(row);
				},
				add: ({ code }) => {
					this.openSave(code);
				},
				edit: () => {
					this.edit();
				},
			},
			gridOps: {},
		};
	},
	methods: {
		openSave: function () {
			this.dialog.save = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open();
			});
		},
		categoryselect: function (data, ids) {
			this.$refs.xGrid1.search("category_id", ids, "in");
			this.handleSuccess();
		},
		handleSuccess() {
			this.$refs.xGrid1.refresh();
		},
		edit(item) {
			let selected = {};
			if (typeof item == "undefined") {
				let selects = this.$refs.xGrid1.xGrid.getCheckboxRecords();
				if (selects.length == 0) {
					this.$message.error("必须选中元素");
					return;
				} else {
					selected = selects[0];
				}
			} else selected = item;
			this.dialog.save = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("edit").setData(selected);
			});
		},
		async del() {
			let selected = this.$refs.xGrid1.xGrid.getCheckboxRecords();
			if (selected.length == 0) {
				ElNotification.error({
					title: "错误",
					message: "必须选中元素",
				});
				return;
			}
			let ids = [];
			selected.forEach((element) => {
				ids.push(element.id);
			});
			var res =
				await this.$API.basedata.businessCompany.category.delete.post({
					ids: ids,
				});
			this.isSaveing = false;
			if (res.code == 200) {
				this.$emit("success", this.form, this.mode);
				this.visible = false;
				this.$refs.xGrid1.refresh();
				this.$message.success("操作成功");
			} else {
				this.$alert(res.message, "提示", { type: "error" });
			}
		},
	},
};
</script>
